<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../resources/tmpl/catalog_layout.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form id="form-content">
            <p:growl id="growl-content" life="3000" />
            <p:panel id="panel-content" header="#{messages.panelTitle} #{roles.entityName}">
                <p:toolbar id="toolbar-content">
                    <p:toolbarGroup align="left">
                        <p:button title="#{messages.homeButton}" icon="ui-icon-home" outcome="list" />
                    </p:toolbarGroup>
                    <p:toolbarGroup align="right">
                        <p:commandButton title="#{messages.newButton}" icon="ui-icon-document" actionListener="#{roles.newEvent(event)}" oncomplete="dlg.show()" 
                                         update=":dialog-content" />
                        <p:commandButton title="#{messages.editButton}" icon="ui-icon-pencil" actionListener="#{roles.editEvent(event)}" oncomplete="dlg.show()" 
                                         disabled="#{roles.disableButtons}" update=":dialog-content" />
                        <p:commandButton title="#{messages.deleteButton}" icon="ui-icon-trash" actionListener="#{roles.remove(event)}"
                                         disabled="#{roles.disableButtons}" update=":form-content" /> 
                    </p:toolbarGroup>
                </p:toolbar>
                <hr/>
                <p:dataTable id="data-table-content" var="rol" value="#{roles.selectable}" selection="#{roles.selected}"
                             selectionMode="single" paginator="true" rows="10" emptyMessage="#{messages.noData}">

                    <p:ajax event="rowSelect" listener="#{roles.onRowSelect}" update=":form-content" />
                    <p:ajax event="rowDblselect" listener="#{roles.onDblSelect}" update=":form-content" />

                    <p:column filterBy="#{rol.name}" headerText="#{messages.nameColumn}" sortBy="#{rol.name}">
                        <h:outputText value="#{rol.name}" />
                    </p:column>

                    <p:column headerText="#{messages.descriptionColumn}">                    
                        <h:outputText value="#{rol.description}" />
                    </p:column>                      
                </p:dataTable>
            </p:panel>
        </h:form>

        <p:dialog id="dialog-content" header="#{roles.titleDialog}" widgetVar="dlg" modal="true" closable="false">
            <h:form id="form-dialog-content">
                <p:panelGrid>
                    <p:row>
                        <p:column>
                            <p:outputLabel for="name" value="#{messages.nameColumn}" />                            
                        </p:column>
                        <p:column>
                            <p:inputText id="name" value="#{roles.selected.name}" 
                                         required="true" requiredMessage="#{messages.required}">
                                <f:validateLength minimum="5" maximum="150">#{messages.lengthName}</f:validateLength>
                            </p:inputText>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column>
                            <p:outputLabel for="description" value="#{messages.descriptionColumn}" />
                        </p:column>
                        <p:column>
                            <p:inputTextarea id="description" value="#{roles.selected.description}" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="2">
                            <p:commandButton value="#{messages.saveButton}" icon="ui-icon-disk" action="#{roles.edit(event)}" 
                                             update=":form-content :form-dialog-content" oncomplete="handleDialogRequest(xhr, status, args)" />
                            <p:button value="#{messages.cancelButton}" icon="ui-icon-close" outcome="roles" />   
                        </p:column>
                    </p:row>
                </p:panelGrid>
            </h:form>
        </p:dialog>
    </ui:define>
</ui:composition>